package Servlets.yz;

import Bean.supplier;
import Util.GokJDBCUtil2;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.Part;

import java.awt.*;
import java.io.*;
import java.time.LocalDateTime;
import java.util.UUID;

/*
* 用于供应商的添加功能
* */
@WebServlet(name="AddSupplyServlet" , urlPatterns = "/AddSupplyServlet")
public class AddSupplyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        /**************************************************************************/
        String supplierenterprise = req.getParameter("supplierenterprise");//企业名
        String supplyName = req.getParameter("supplyName");//供应商人的姓名
        String supplierphone = req.getParameter("supplierphone");//供应商电话
        String supplieraddress = req.getParameter("supplieraddress");//供应商地址
        String supplieremail = req.getParameter("supplieremail");//供应商电子邮件
        LocalDateTime createtime = LocalDateTime.now();//获取当前时间
        /**************************************************************************/
        //插入指定列和指定值
        String sql1 = "insert into supplier (name,contactperson,phonenumber,email,address,createtime) values(?,?,?,?,?,?)";
        GokJDBCUtil2.update(sql1,supplierenterprise,supplyName,supplierphone,supplieremail,supplieraddress,createtime);
        //请求转发
        resp.sendRedirect(req.getContextPath()+"/pages/AddSupplySuccess.jsp");
        writer.close();
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
